#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};

int sumNumbers(TreeNode* root) {
    return sum(root, 0);
}

int sum(TreeNode* root, int val)
{
    if (root->left == nullptr && root->right == nullptr)
    {
        return val * 10 + root->val;
    }

    int left = 0;
    int right = 0;

    if (root->left)
        left = sum(root->left, val * 10 + root->val);
    if (root->right)
        right = sum(root->right, val * 10 + root->val);

    return right + left;
}

int main()
{


	return 0;
}